package Demo3;

import Demo2.Booklist;

import java.util.Scanner;

public class Borrow implements IFuntion{
    @Override
    public void work(Booklist booklist) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入需要借阅的书籍名称:>");
        String bookName = scanner.nextLine();
        //遍历数组
        int sz = booklist.getCount();
        int i = 0 ;
        for (; i < sz; i++) {
            if(booklist.getBook(i).getName().equals(bookName)){
                break;//找到了
            }
        }
        if(sz == i) System.out.println("需要借阅的书籍不存在！");
        //已经借阅
        else {
            if (booklist.getBook(i).borrowed == true) {
                System.out.println("此书籍已经借阅！");
            } else {
                System.out.println("此书籍可以借阅！");
            }
            booklist.getBook(i).borrowed = true;
            System.out.println("已登记，可以借出！");
        }
    }
}
